<?php if (!defined('SERVER_ROOT')) exit('No direct script access allowed');

class canbo_Controller extends Controller {
    function __construct(){
        parent::__construct('qlcb', 'canbo');
        $this->check_login();
        $this->view->template->menu_html =$this->CREATE_MENU();
        $this->view->template->nhacviec_html =$this->CREATE_NHAC_VIEC(); 
        $this->CHECK_QUYEN('qlcb', 'canbo');
    }
    function main(){
        (Session::get(TIEP_DAU_NGU_SESSION.'QUAN_TRI') == 1) Or die($this->access_denied());
        $this->dsp_all_canbo();
    }
    /****************************form canbo***********************/
    private function _save_filter(){
        $v_TYPE_filter = $this->get_post_var('hdn_TYPE_filter');
        $v_MA_DON_VI_filter = $this->get_post_var('cbx_MA_DON_VI_filter');
        $v_MA_TO_CHUYEN_MON_filter = $this->get_post_var('cbx_MA_TO_CHUYEN_MON_filter');
         //   echo '<script>alert("update type: '.$v_MA_TO_CHUYEN_MON_filter.'");</script>';
        if($v_TYPE_filter == ''){
           $v_TYPE_filter = 'MA_DON_VI';
           $v_MA_TO_CHUYEN_MON_filter = 0;
        }
        if($v_MA_TO_CHUYEN_MON_filter == ''){
           $v_MA_TO_CHUYEN_MON_filter = 0;
        }
        return array(
            'hdn_TYPE_filter'   => $v_TYPE_filter,
            'cbx_MA_DON_VI_filter'=> $v_MA_DON_VI_filter,
            'cbx_MA_TO_CHUYEN_MON_filter'=> $v_MA_TO_CHUYEN_MON_filter,
        );
    }
    function dsp_all_canbo(){
        (Session::get(TIEP_DAU_NGU_SESSION.'QUAN_TRI') == 1) Or die($this->access_denied());
        $arr_filter = $this-> _save_filter();
        $P_TYPE = $arr_filter['hdn_TYPE_filter'];
        if ($P_TYPE == 'MA_DON_VI'){
            $P_MA_DON_VI = $arr_filter['cbx_MA_DON_VI_filter'];
            $VIEW_DATA['arr_filter']       = $arr_filter;
            $VIEW_DATA['arr_all_donvi_filter']       = $this->model->SELECT_DONVI_tatca();
            $VIEW_DATA['arr_all_tochuyenmon_filter'] = $this->model->SELECT_TOCHUYENMON_by_mdv($P_MA_DON_VI);
            $VIEW_DATA['arr_all_canbo']= $this->model->SELECT_CAN_BO_BY_MDV_ALL_TR($P_MA_DON_VI);

        }else{
            $P_MA_DON_VI = $arr_filter['cbx_MA_DON_VI_filter'];
            $P_MA_TO_CHUYEN_MON = $arr_filter['cbx_MA_TO_CHUYEN_MON_filter'];
            $VIEW_DATA['arr_filter']       = $arr_filter;
            $VIEW_DATA['arr_all_donvi_filter']       = $this->model->SELECT_DONVI_tatca();
            $VIEW_DATA['arr_all_tochuyenmon_filter'] = $this->model->SELECT_TOCHUYENMON_by_mdv($P_MA_DON_VI);
            $VIEW_DATA['arr_all_canbo']= $this->model->SELECT_CAN_BO_BY_MTCM_ALL_TR($P_MA_DON_VI,$P_MA_TO_CHUYEN_MON);
        }
        $this->view->render('dsp_all_canbo', $VIEW_DATA);
    }
    function dsp_all_canbo_to(){
        (Session::get(TIEP_DAU_NGU_SESSION.'QUAN_TRI') == 1) Or die($this->access_denied());
        $v_m                      = trim(get_request_var('m'));
        $VIEW_DATA['var_matochuyemon'] = $v_m;
        $VIEW_DATA['arr_single_tochuyenmon'] = $this->model->qry_single_tochuyenmon($v_m);
        $VIEW_DATA['arr_all_canbo']        = $this->model->SELECT_CAN_BO_BY_MTCM_ALL_TR2($v_m);
        $this->view->render('dsp_all_canbo_to', $VIEW_DATA);
    }
    function dsp_canbo_chuaphancongtac(){
        (Session::get(TIEP_DAU_NGU_SESSION.'QUAN_TRI') == 1) Or die($this->access_denied());
        $VIEW_DATA['arr_all_canbo'] = $this->model->SELECT_CAN_BO_CHUA_PHAN_CT();
        $this->view->render('dsp_canbo_chuaphancongtac',$VIEW_DATA);
    }
    public function dsp_single_canbo(){
        (Session::get(TIEP_DAU_NGU_SESSION.'QUAN_TRI') == 1) Or die($this->access_denied());
        $v_m                      = trim(get_request_var('m'));
        $VIEW_DATA['var_macanbo'] = $v_m;
        $VIEW_DATA['arr_single_canbo'] = $this->model->qry_single_canbo($v_m);
        $VIEW_DATA['arr_all_dantoc'] = $this->model->SELECT_DANTOC_nothing();
        $VIEW_DATA['arr_all_tongiao'] = $this->model->SELECT_TONGIAO_nothing();
        $VIEW_DATA['arr_all_quoctich'] = $this->model->SELECT_QUOCTICH_nothing();
        $VIEW_DATA['arr_all_hocham'] = $this->model->SELECT_HOCHAM_nothing();
        $VIEW_DATA['arr_all_hocvi'] = $this->model->SELECT_HOCVI_nothing();
        $VIEW_DATA['arr_all_loaicanbo'] = $this->model->SELECT_LOAICANBO_nothing();
        $this->view->render('dsp_single_canbo', $VIEW_DATA);
    }
    public function update_canbo(){
        (Session::get(TIEP_DAU_NGU_SESSION.'QUAN_TRI') == 1) Or die($this->access_denied());
        $P_TYPE = get_post_var('hdn_update_type');
         if($P_TYPE=='CAP_NHAT'){
              $m = get_post_var('txt_MA_CAN_BO');
          } else{
              $m = 0;
          }
        $this->model->goback_url = $this->view->get_controller_url() . 'dsp_single_canbo/&m='.$m;
        $this->model->update_canbo();
    }
    public function delete_canbo(){
        (Session::get(TIEP_DAU_NGU_SESSION.'QUAN_TRI') == 1) Or die($this->access_denied());
        $this->model->goback_url = $this->view->get_controller_url() . 'dsp_all_canbo';
        $this->model->delete_canbo();
    }
    /****************************form dsp_phanto_canbo***********************/
    function dsp_all_to_of_canbo($MA_CAN_BO) {
        (Session::get(TIEP_DAU_NGU_SESSION.'QUAN_TRI') == 1) Or die($this->access_denied());
        $MA_CAN_BO = replace_bad_char($MA_CAN_BO);
        $VIEW_DATA['arr_single_canbo'] = $this->model->qry_single_canbo($MA_CAN_BO);
        $VIEW_DATA['arr_all_to_of_canbo'] = $this->model->SELECT_ALL_TO_OF_CANBO($MA_CAN_BO);
        $this->view->render('dsp_all_to_of_canbo', $VIEW_DATA);
    }
    function dsp_themnoicongtac($MA_CAN_BO) {
        (Session::get(TIEP_DAU_NGU_SESSION.'QUAN_TRI') == 1) Or die($this->access_denied());
        $VIEW_DATA['var_macanbo'] = $MA_CAN_BO;
        $VIEW_DATA['arr_all_donvi'] = $this->model->SELECT_DONVI_chon();
        $VIEW_DATA['arr_all_chucvu'] = $this->model->SELECT_CHUCVU_chon();
        $this->view->render('dsp_themnoicongtac', $VIEW_DATA);
   }
   public function dsp_cbx_tochuyenmon($MA_DON_VI) {
        (Session::get(TIEP_DAU_NGU_SESSION.'QUAN_TRI') == 1) Or die($this->access_denied());
        $VIEW_DATA['arr_all_tochuyenmon'] = $this->model->SELECT_TOCHUYENMON_by_mdv($MA_DON_VI);
        $this->view->render('dsp_cbx_tochuyenmon', $VIEW_DATA);
    }
   function insert_thuocto() {
        (Session::get(TIEP_DAU_NGU_SESSION.'QUAN_TRI') == 1) Or die($this->access_denied());
        $this->model->goback_url = $this->view->get_controller_url() . 'dsp_all_to_of_canbo';
        $this->model->insert_thuocto();
    }
    function dsp_capnhatcongtac($P_MA_CAN_BO) {
        (Session::get(TIEP_DAU_NGU_SESSION.'QUAN_TRI') == 1) Or die($this->access_denied());
        $VIEW_DATA['var_macanbo'] = $P_MA_CAN_BO;
        $P_MA_TO_CHUYEN_MON                   = trim(get_request_var('mato'));
        $P_MA_CHUC_VU               = trim(get_request_var('machucvu'));
        $P_TU_NGAY                 = trim(get_request_var('tungay'));
        $VIEW_DATA['arr_thuoc_to_detail'] = $this->model->SELECT_THUOC_TO_DETAIL
                                                          ($P_MA_CAN_BO,
                                                           $P_MA_TO_CHUYEN_MON,
                                                           $P_MA_CHUC_VU,
                                                           $P_TU_NGAY);
        $this->view->render('dsp_capnhatcongtac', $VIEW_DATA);
   }
   function update_thuocto() {
        (Session::get(TIEP_DAU_NGU_SESSION.'QUAN_TRI') == 1) Or die($this->access_denied());
        $this->model->goback_url = $this->view->get_controller_url() . 'dsp_all_to_of_canbo';
        $this->model->update_thuocto();
    }
    /****************************form dsp_all_nhomquyen***********************/
    public function dsp_all_nhomquyen($MA_CAN_BO){
        (Session::get(TIEP_DAU_NGU_SESSION.'QUAN_TRI') == 1) Or die($this->access_denied());
        $MA_CAN_BO  = replace_bad_char($MA_CAN_BO);
        $TEN_CAN_BO = replace_bad_char($_REQUEST['hdn_item_name']);
        $VIEW_DATA['var_macanbo'] = $MA_CAN_BO;
        $VIEW_DATA['var_tencanbo'] = $TEN_CAN_BO;
        $VIEW_DATA['arr_all_nhomquyen'] = $this->model->SELECT_ALL_NHOM_QUYEN_CAN_BO($MA_CAN_BO);
        $this->view->render('dsp_all_nhomquyen', $VIEW_DATA);
    }
    public function update_nhomquyencanbo()
    {
        (Session::get(TIEP_DAU_NGU_SESSION.'QUAN_TRI') == 1) Or die($this->access_denied());
        $this->model->goback_url = $this->view->get_controller_url() . 'dsp_all_loaidonvi';
        $this->model->update_nhomquyencanbo();
    }
}
